<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

class Tag extends Base
{
	/**
	 * 禁止被批量赋值的字段
	 *
	 * @var array
	 */
	protected $guarded = [];
	
	// 软删除
	use SoftDeletes;
	
	/**
	 * 关联文章表
	 * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
	 */
	public function article()
	{
		return $this->belongsToMany(Article::class, "article_tags");
	}
	
	public function storeData($data)
	{
		
		//根据是否有id判断修改还是添加
		if (isset($data['id']) && $data['id']) {
			$this->where('id', $data['id'])->update($data);
		} else {
			$this->create($data);
		}
	}
}
